<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/14
 * Time: 15:40
 */
session_start();
$num=$_POST['num'];
$name=$_POST['name'];
include '../classes/conn.php';
if(isset($_SESSION['admin_num'])) {
    $query="select num from teacher where num='{$num}'";
    $res=mysql_query($query);
    if(mysql_num_rows($res)){
        die('exist');
    }
    $query="select name from teacher where name='{$name}'";
    $res=mysql_query($query);
    if(mysql_num_rows($res)){
        die('exist');
    }
    $psw=md5(substr($num, -6));
    $query="insert into teacher (num,name,psw) values ('{$num}','{$name}','{$psw}')";
    mysql_query($query);
    mysql_close($conn);

//    创建文件夹
    $dir='../Files/'.$num;
    if(!file_exists($dir)) {
        if (mkdir($dir)) {
            $dir1=$dir.'/courseware';
            $dir2=$dir.'/homework';
            $dir2_1=$dir2.'/attach';
            $dir2_2=$dir2.'/submit';
            $dir2_3=$dir2.'/answer';
            $dir3=$dir.'/shared';
            $dir4=$dir.'/private';
            $dir5=$dir.'/namelist';
            if(!file_exists($dir1)){
                mkdir($dir1);
            }
            if(!file_exists($dir2)){
                mkdir($dir2);
            }
            if(!file_exists($dir2_1)){
                mkdir($dir2_1);
            }
            if(!file_exists($dir2_2)){
                mkdir($dir2_2);
            }
            if(!file_exists($dir2_3)){
                mkdir($dir2_3);
            }
            if(!file_exists($dir3)){
                mkdir($dir3);
            }
            if(!file_exists($dir4)){
                mkdir($dir4);
            }
            if(!file_exists($dir5)){
                mkdir($dir5);
            }
            echo '1';
        }
    }
    else echo 'error';
}
else echo "no_login";